/**
 *  Copyright (c) 2005 by David Bridgewater
 *  All rights reserved.
 *  
 *  You may study, use, modify, and distribute this
 *  software for any purpose provided that this
 *  copyright notice appears in all copies.
 *  
 *  This software is provided without warranty
 *  either expressed or implied.
 */
package webcert.ch02.ex0202;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * 
 * A servlet which displays its own initialization parameters -
 * whatever they may be.
 *  
 */
public class ShowInitParams extends HttpServlet {

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        /* Set the response type, retrieve the writer */
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.write("<HTML><HEAD><TITLE>" + "Show Initialization Parameters "
                + "Servlet</TITLE></HEAD><BODY>");
        out.write("<H1>Show Initialization Parameters Servlet</H1>");

        /* Retrieve the names and display names and values */
        Enumeration paramNames = getInitParameterNames();
        int parmCount = 0;
        while (paramNames.hasMoreElements()) {
            String name = (String) paramNames.nextElement();
            String value = getInitParameter(name);
            out.write("<H4>The parameter with name " + name
                    + " has a value of " + value + "</H4>");
            parmCount++;
        }

        if (parmCount == 0) {
            out
                    .write("<H2><FONT color=red>There were no initialization parameters!</FONT></H2>");
        }
        /* Tidy up */
        out.write("</BODY></HTML>");
        out.flush();
        out.close();

    }


}